package com.dd.test;

public class Link {
	
	public Link next;
	
	public String data;
	
	public Link(Link next,String currentNodeData){
		this.next = next;
		this.data = currentNodeData;
	}

	//null->1->2->5->7->9->11->12->23
	public static Link generateLink(){
		Link e8 = new Link(null,"23");
		Link e7 = new Link(e8,"12");
		Link e6 = new Link(e7,"11");
		Link e5 = new Link(e6,"9");
		Link e4 = new Link(e5,"7");
		Link e3 = new Link(e4,"5");
		Link e2 = new Link(e3,"2");
		Link e1 = new Link(e2,"1");
		Link head = new Link(e1,null);
		
		return head;
		
	}
	
	public static void traverse(){
		Link head = generateLink();
		Link cur = head;
		while(cur!=null){
			System.out.println(cur.data);
			cur = cur.next;
		}
		
		
	}
	
	public static void reversedTraversePrint(Link head){
		
        if(head!=null){
		reversedTraversePrint(head.next);
		System.out.println(head.data);
        }
		
		}
		
		
	
	
	public static void main(String[] args){
      traverse();
      System.out.println("-------------------------------------");
      Link head = generateLink();
      reversedTraversePrint(head);
      
	}
}
